package mutil.thread;

/**
 * Created by luoqifei on 2017/7/13.
 * yield 是不会释放对象锁的
 * yield只是让出执行权，不会释放对象锁
 */
public class YieldTest extends Thread{
    public static Object obj = new Object();
    public YieldTest(String threadName){
        super(threadName);
    }
    public synchronized void run(){
        synchronized (obj) {
            for (int i = 0; i < 10; i++) {
                System.out.printf("%s [%d]:%d\n", this.getName(), this.getPriority(), i);
                if (i % 4 == 0) {
                    this.yield();
                }
            }
        }
    }

    public static void main(String[] args) {
        YieldTest testA = new YieldTest("threadA");
        YieldTest testB = new YieldTest("threadB");
        testA.start();
        testB.start();
    }
}
